import Moya

enum CameraService {
    case getOSSUrl
}

extension CameraService: TargetType {
    func getToken() -> String {
        // 这里使用伪造的 token 来作为示例，实际应该是你自己的生成 token 逻辑。
        return "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxODk4MjQ3Mjc4NiIsImV4cCI6MTY4MzkxNzc1Nn0.YDaZVQK5D4IEjTAQJmrbG7Cb4H4IxNRvCEOdZ5EsiZA"
    }

    var baseURL: URL {
        return URL(string: "http://106.14.226.26:8080/fun-skincare")!
    }

    var path: String {
        switch self {
        case .getOSSUrl:
            return "/oss/getOssSign"
        }
    }

    var method: Method {
        switch self {
        case .getOSSUrl:
            return .get
        }
    }

    var sampleData: Data {
        return Data()
    }

    var task: Task {
        switch self {
        case .getOSSUrl:
            return .requestPlain
        }
        //表示没有参数的网络请求
        //case .getUsers(let userId):
       // return .requestParameters(parameters: ["userId": userId], encoding: JSONEncoding.default)
    }

    var headers: [String : String]? {
        return ["Content-type": "application/json"]
    }
}

let endpointClosure = { (target: CameraService) -> Endpoint in
    let defaultEndpoint = MoyaProvider.defaultEndpointMapping(for: target)
    let token = target.getToken()
    return defaultEndpoint.adding(newHTTPHeaderFields: ["Authorization": "Bearer \(token)"])
}

let camera_provider = MoyaProvider<CameraService>(endpointClosure: endpointClosure)

